package com.lovestudying.service.impl;

import java.util.HashMap;
import java.util.Map;

import com.lovestudying.dao.CommentDao;
import com.lovestudying.dao.LikelistDao;
import com.lovestudying.dao.ReplyDao;
import com.lovestudying.dao.Impl.CommentDaoImpl;
import com.lovestudying.dao.Impl.LikelistDaoImpl;
import com.lovestudying.dao.Impl.ReplyDaoImpl;
import com.lovestudying.service.LikeListService;
import com.lovestudying.util.DBUtil_Pro;

public class LikeListServiceImpl implements LikeListService {
	LikelistDao LikelistDao = new LikelistDaoImpl();
	CommentDao CommentDao = new CommentDaoImpl();
	ReplyDao ReplyDao = new ReplyDaoImpl();

	@Override
	public Boolean addALike(String accountId, String objId) {

		Map<String, Object> Value_Param = new HashMap<>();
		String likeTime = DBUtil_Pro.GetNowTime();
		Value_Param.put("account_id", accountId);
		Value_Param.put("object_id", objId);
		Value_Param.put("like_time", likeTime);
		if (LikelistDao.InsertLike(Value_Param) == 1) {
			Map<String, Object> setParamForRep = new HashMap<>();
			ReplyDao.addAlike(objId);
			CommentDao.addAlike(objId);
			return true;
		} else {
			return false;
		}
	}

	@Override
	public Boolean getCommentLikeState(String nowAccount, String comment_id) {
		Map<String, Object> Where_Param = new HashMap<>();
		Where_Param.put("like_list.account_id", nowAccount);
		Where_Param.put("like_list.object_id", comment_id);
//		LikelistDao.findLikeUniAccount(Where_Param, null, null, null);
		if (LikelistDao.findLikeUniAccount(Where_Param, null, null, null).getData().size() == 0) {
			return false;
		} else {
			return true;
		}
	}

	@Override
	public Boolean cancelLike(String accountId, String objId) {

		Map<String, Object> Where_Param = new HashMap<>();
		Where_Param.put("account_id", accountId);
		Where_Param.put("object_id", objId);
		if (LikelistDao.DeleteLike(Where_Param) == 1) {
			Map<String, Object> setParamForRep = new HashMap<>();
			ReplyDao.cancelALike(objId);
			CommentDao.cancelALike(objId);
			return true;
		} else {
			return false;
		}
	}

}
